﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Admin_AdminInformation : System.Web.UI.Page
{
    string _ADID = "";
    AddminMethord AM = new AddminMethord();
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            _ADID = Session["User"].ToString();
            if (!IsPostBack)
            {
                Admininformation();
            }
            btnSave.Visible = false;
            txtAddress.Enabled = false;
            txtBirthOfDate.Enabled = false;
            txtEmail.Enabled = false;
            txtFullName.Enabled = false;
            txtPhone.Enabled = false;
            txtUserName.Enabled = false;
            btnCancel.Visible = false;
            txtUserName.Enabled = false;
        }
        catch (Exception ex)
        {
        }
    }
    public void Admininformation() { 
        DataTable tb = AM.AdminInformation(_ADID);
        if(tb.Rows.Count > 0)
        {
            txtUserName.Text = tb.Rows[0]["UserName"].ToString();
            txtFullName.Text = tb.Rows[0]["FullName"].ToString();
            txtAddress.Text = tb.Rows[0]["Address"].ToString();
            txtPhone.Text = tb.Rows[0]["Phone"].ToString();
            txtBirthOfDate.Text = tb.Rows[0]["BirthOfDate"].ToString().Substring(0, tb.Rows[0]["BirthOfDate"].ToString().IndexOf(" "));
            txtEmail.Text =  tb.Rows[0]["EmailID"].ToString();
            
        }
    }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        Response.Redirect("AddminHome.aspx");
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        btnSave.Visible = true;
        txtAddress.Enabled = true;
        txtBirthOfDate.Enabled = true;
        txtEmail.Enabled = true;
        txtFullName.Enabled = true;
        txtPhone.Enabled = true;
        txtUserName.Enabled = true;
        btnUpdate.Visible = false;
        btnCancel.Visible = true;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        //string fulname = txtFullName.Text;
        //string address = txtAddress.Text;
        if(txtPhone.Text == null)
        {
            lblErors.Text += "Please Enter Phone";
        }
        if(txtFullName.Text == null)
        {
            lblErors.Text += "Please Enter FullName";
        }
        if(txtEmail.Text == null){
            lblErors.Text += "Please Enter Email";
        }
        if(txtAddress.Text == null)
        {
            lblErors.Text += "Please Enter Address";            
        }
        if(txtBirthOfDate.Text == null)
        {
            lblErors.Text += "Please Enter BirthOfDate";            
        }
        
        try
        {
            bool check = AM.UpdateAddmin(txtFullName.Text, txtAddress.Text, txtPhone.Text, Convert.ToDateTime(txtBirthOfDate.Text), txtEmail.Text, txtUserName.Text);
            if (check == true)
            {
                lblErors.Text = "Update succsess";
            }
            else
            {
                lblErors.Text = "update false";
            }
        }
        catch (Exception ex)
        {
        }
        
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Admininformation();
        btnSave.Visible = false;
        txtAddress.Enabled = false;
        txtBirthOfDate.Enabled = false;
        txtEmail.Enabled = false;
        txtFullName.Enabled = false;
        txtPhone.Enabled = false;
        txtUserName.Enabled = false;
        btnCancel.Visible = false;
        btnUpdate.Visible = true;
    }
}